import { exec } from 'child_process';

const fileName = 'README.md'; // Replace with the path to your file

// Git command to get history of a file
const gitCommand = `git log --follow --stat -- ${fileName}`;

exec(gitCommand, (error, stdout, stderr) => {
  if (error) {
    console.error(`Error executing the command: ${error}`);
    return;
  }
  if (stderr) {
    console.error(`Git command had errors: ${stderr}`);
    return;
  }

  console.log(`Git history of ${fileName}:`);
  ///////////////////////////////////////////////////
  const foundCommits = findCommits(stdout);
  console.log("Found commits:");
  console.log(foundCommits);
  //console.log(stdout);
});

function findCommits(gitLogOutput: string): string[] {
  const regex = /[0-9a-f]{40}/g; // Assuming commit hashes are 40-character SHA-1 hashes
  const matches = gitLogOutput.match(regex) || [];
  return matches;
}

/////////////////////////////////////////////////////////////////////////////
let commitId = "dfa09f697149b7adcfee3a212a3aea11b17c7e37";
const gitShowData = `git show ${commitId}:${fileName}`;
exec(gitShowData, (error, stdout, stderr) => {
  console.log(stdout);
});

